include io.asm

stack segment stack
	dw 128 dup (?)
stack ends

;;======================================================================
data segment
	Head db "Vasilenko Anatoly. Group 111.$"
	Input db "Enter please number: $"
	Output db "Answer: $"
	numeral db "0123456789ABCDEF$"
	answer db 4 dup (' '), '$';
data ends
;;======================================================================

code segment 'code'
	assume ss:stack, ds:data, cs:code
start:
	mov ax,data
	mov ds,ax
	lea dx, Head
	outstr
	newline
	newline
	;;------------------------------------------------------------------
		lea dx, Input;
		outstr;
		
		xor ax, ax
		L1:	inch dl;
			
			cmp dl, ' ';
			je break1;
			
			cmp dl, '9';
			jae let;
			sub dl, '0';
			jmp short num;
			let:
			sub dl, 'A'-10;
			num:
			
			mov cl, 4;
			shl ax, cl;
			or al, dl;
		jmp L1;
		break1:
		
		; there is a number in 'ax'
		
		mov cx, 4;
		L2:	mov bx, ax;
			and bx, 1111b;
			push cx;
			mov cl, 4;
			shr ax, cl;
			pop cx;
			
			mov si, cx;
			mov dl, numeral[bx];
			mov answer[si-1], dl
			cmp ax, 0;
		loopne L2;
		
		lea dx, Output;
		outstr;
		lea dx, answer[si-1];
		outstr;
	;;------------------------------------------------------------------

the_end:
	newline;
	mov ah,8
	int 21h
    finish
code ends

;;======================================================================
end start 

;;======================================================================
